package classroom;

import java.io.*;
import java.text.DecimalFormat;

public class Test2 {
    public static void main(String[] args) throws Exception {
        File src = new File("Day15\\QQMusic(1802.5318)20210630184644.logH.zip");
        File dest = new File("D:\\QQMusicCache\\Log\\QQMusic\\QQMusic(1802.5318)20210630184644.logH.zip");

        DecimalFormat df = new DecimalFormat("##%");
        long totalLength = src.length();//获取文件大小

        //高效字节，拷贝
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(src));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(dest));

        byte [] arr = new byte[1024*8];
        //定义累加每次读到字节数量
        int sum_len =0;
        int len ;
        while ((len = bis.read(arr))!=-1){
            bos.write(arr,0,len);
            sum_len +=len ;
            String format = df.format(1.0 * sum_len / totalLength);
            System.out.println(src.getName()+"文件复制"+format);
        }
        bis.close();
        bos.close();
    }
}
